package com.config;

import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.concurrent.atomic.AtomicInteger;


public class OrderNumber {
	static AtomicInteger atomicInteger = new AtomicInteger();
	//实现生成订单号
	//生成规则:年月日時分秒+00001~00099
	public static String toDateString() {
		Calendar calendar = new GregorianCalendar();
		int year = calendar.get(Calendar.YEAR);//年
		int month = calendar.get(Calendar.MONTH)+1;//月
		int day = calendar.get(Calendar.DAY_OF_MONTH);//日
		int hours = calendar.get(Calendar.HOUR_OF_DAY);//时
		int minute = calendar.get(Calendar.MINUTE);//分
		int second = calendar.get(Calendar.SECOND);//秒
		int mil = calendar.get(Calendar.MILLISECOND);//毫秒
		int am = atomicInteger.getAndIncrement();
		String str="";
		if(am>999) {
			atomicInteger = new AtomicInteger();
		}
		if(am<100) {
			str="" + year + "0"+month +"0"+ day +hours+minute+second+"000"+ am;
		}else {
			str="" + year + "0"+month +"0"+ day +hours+minute+second+"00"+ am;
		}
		return str;     
	}
}
